layui.use(['table','layer','form','jquery'],function () {

    //Layui的组件
    var table = layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.jquery;

    //项目名称
    var basePath = $("#basePath").val();

   var tableInf = table.render({
        elem:'#classTable',//id选择器的值
        toolbar:'#classToolbar',//头工具栏
        url:basePath+'/findAllandmohu',
        method:'post',
        contentType:'application/json',
        title:'教室表信息',
        page:true,//开启分页
        limit:5,//分页的条数（默认是10）
        limits:[1,2,3,4,5,6,7,8,9],//分页下拉框选项
        cols: [
            [
                {
                    type: 'checkbox',
                    fixed: 'left',
                    width: 60
                },
                {
                    field: 'area',
                    title: '区域',
                    align: 'center',
                    width: 80,
                }, {
                field: 'buildingNo',
                title: '楼号',
                align: 'center',
                width: 140
            }, {
                field: 'buildingFloor',
                title: '楼层',
                align: 'center',
                width: 80
            }, {
                field: 'classroomNumber',
                title: '教室编号',
                align: 'center',
                width: 100
            }, {
                field: 'classroomName',
                title: '教室名称',
                align: 'center',
                width: 140
            }, {
                field: 'galleryful',
                title: '容纳人数',
                align: 'center',
                width: 80
            }, {
                field: 'useStatus',
                title: '使用状态',
                align: 'center',
                width: 120,
            },  {
                field: 'createTime',
                title: '创建时间',
                align: 'center',
                width: 160,
            }, {
                field: 'updateTime',
                title: '修改时间',
                align: 'center',
                width: 160,
            }, {
                fixed: 'right',
                width: 248,
                title: '操作',
                align: 'center',
                toolbar: '#classBar'
            }
            ]
        ],
        done: function (res, curr, count) {
            // 使用情况
            $("[data-field='useStatus']").children().each(function () {
                if ($(this).text() == '0') {
                    $(this).text('使用');
                } else if ($(this).text() == '1') {
                    $(this).text('未使用');
                }else if ($(this).text() == '2') {
                    $(this).text('维修中');
                }
            });

            $("[data-field='area']").children().each(function () {
                if ($(this).text() == 'A') {
                    $(this).text('A区');
                } else if ($(this).text() == 'B') {
                    $(this).text('B区');
                } else if ($(this).text() == 'C') {
                    $(this).text('C区');
                } else if ($(this).text() == 'D') {
                    $(this).text('D区');
                } else if ($(this).text() == 'E') {
                    $(this).text('E区');
                }
            });
            $("[data-field='buildingFloor']").children().each(function () {
                if ($(this).text() == '1') {
                    $(this).text('第一层');
                } else if ($(this).text() == '2') {
                    $(this).text('第三层');
                } else if ($(this).text() == '3') {
                    $(this).text('第三层');
                }
            });
            $("[data-field='buildingNo']").children().each(function () {
                if ($(this).text() == '1') {
                    $(this).text('第一号楼');
                } else if ($(this).text() == '2') {
                    $(this).text('第二号楼');
                } else if ($(this).text() == '3') {
                    $(this).text('第三号楼');
                }
            });

            $("[data-field='createTime']").children().each(function () {
                var birthday = $(this).text();
                if (birthday.indexOf('创建时间') == -1) {
                    $(this).text(getYMDHMS(parseInt(birthday)));
                }
            });

            $("[data-field='updateTime']").children().each(function () {
                var birthday = $(this).text();
                if (birthday.indexOf('修改时间') == -1) {
                    $(this).text(getYMDHMS(parseInt(birthday)));
                }
            });

        }

    });

   $.ajax({
       type: "post",
       url:basePath+"/threexlk",
       contentType: "application/json;charset=utf-8",
       dataType:"json",
       success:function (alsit){
           var  ahtml ="<option value=‘’></option>";
           for (let i = 0; i < alsit.length; i++) {
                ahtml += "<option value="+alsit[i].area+">"+alsit[i].area+"区</option>";
           }
           layer.msg(ahtml);
           $("select[name='area']").html(ahtml);
           form.render("select");
       },error:function (){
           layer.msg("请求失败1");
       }
   });

    //楼号
    form.on('select(area)',function (date) {

        console.info(date.value);

        $.ajax({
            type: "post",
            url:basePath+"/threexlkbn",
            contentType: "application/json;charset=utf-8",
            data:JSON.stringify({area:date.value}),
            dataType:"json",
            success:function (bnlsit){
                var  ahtml ="<option value=‘’></option>";
                for (let i = 0; i < bnlsit.length; i++) {
                    ahtml += "<option value="+bnlsit[i].buildingNo+">第"+bnlsit[i].buildingNo+"号楼</option>";
                }
                layer.msg(ahtml);
                $("select[name='buildingNo']").html(ahtml);
                form.render("select");
            },error:function (){
                layer.msg("请求失败1");
            }


    });
    });


    //模糊查询
    form.on("submit(fuzzyQuery)",function (data) {

        console.info(data.field);  //当前容器的全部表单字段，名值对形式：{name: value}

        tableInf.reload({
            where:data.field,       //模糊查询的条件
            page:{
                curr:1,                 //起始页
            }
        });


        return false;   //阻止表单的跳转
    });






});






// 时间戳
function getYMDHMS(timestamp) {
    let time = new Date(timestamp)
    let year = time.getFullYear()
    const month = (time.getMonth() + 1).toString().padStart(2, '0')
    const date = (time.getDate()).toString().padStart(2, '0')
    const hours = (time.getHours()).toString().padStart(2, '0')
    const minute = (time.getMinutes()).toString().padStart(2, '0')
    const second = (time.getSeconds()).toString().padStart(2, '0')

    return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
}